const BaseModel = require('./base_model.js');

class QAModel extends BaseModel {

    constructor() {
        super();

        this._collection = 'qa_history';
        this._pk = '_id';
        this._db = this.db;
    }

    /**
     * 添加问答记录
     * @param {Object} data 问答数据
     */
    async add(data) {
        return await this.insert({
            ...data,
            ADD_TIME: this.time(),
            EDIT_TIME: this.time(),
            STATUS: 1
        });
    }

    /**
     * 更新问答记录
     * @param {String} id 记录ID
     * @param {Object} data 问答数据
     */
    async edit(id, data) {
        return await this.update(id, {
            ...data,
            EDIT_TIME: this.time()
        });
    }

    /**
     * 删除问答记录
     * @param {String} id 记录ID
     */
    async del(id) {
        return await this.delete(id);
    }

    /**
     * 获取问答记录列表
     * @param {Object} where 查询条件
     * @param {Object} fields 返回字段
     * @param {Object} orderBy 排序
     * @param {Number} page 页码
     * @param {Number} size 分页大小
     */
    async getList(where, fields = '*', orderBy = { ADD_TIME: 'desc' }, page = 1, size = 10) {
        return await this.getAll(where, fields, orderBy, page, size);
    }

    /**
     * 获取问答记录详情
     * @param {String} id 记录ID
     */
    async getDetail(id) {
        return await this.getOne(id);
    }
}

module.exports = QAModel; 